#pragma once
#include <iostream>
#include <string>
#include "json/json.h"
#include <opencv2/opencv.hpp>
#include <vector>
#include <map>
#include <fstream>
#include <boost/variant.hpp>
#include "ParamProcessing.h"
#include "CommandParameters.h"
#include "base64.h"
#include "log.h"
#include "ImageHandle.h"
#include "Server.h"

using VariantType = boost::variant<int, std::string, cv::Mat, DetectionResult, std::vector<cv::Point2f>>;

// 建立map类型图像处理函数映射表
const std::map<std::string, int> ImageHandleNum =
    {
        {"Frame", 1},
        {"Binarization", 2},
        {"BrightnessEnforce", 3},
        {"Color2Gray", 4},
        {"CircleRecognition", 5},
        {"RectangleRecognition", 6},
        {"PatternRecognition", 7},
        {"Mapping", 8},
        {"SendData", 9}};

struct ProcessNode
{
    int ID;
    std::string CName;
    std::string Name;
    Json::Value Parameter;
    int Parent;
    std::vector<int> Children;
};

class ProcessTree
{
public:
    ProcessTree(const std::string &jsonFile);
    std::map<int, VariantType> execute();

private:
    Json::Value processTreeJson;
    std::map<int, ProcessNode> nodes;
    std::map<int, VariantType> results;

    void parseProcessTree();
    void executeNode(int nodeId);
};
